import utils from '@/assets/js/utils'
import {_API} from  '@/assets/api/http'


const jsApiList = [
	
	'updateAppMessageShareData',
	'updateTimelineShareData',
	'onMenuShareWeibo',
	'onMenuShareQZone',
	'startRecord',
	'stopRecord',
	'onVoiceRecordEnd',
	'playVoice',
	'pauseVoice',
	'stopVoice',
	'onVoicePlayEnd',
	'uploadVoice',
	'downloadVoice',
	'chooseImage',
	'previewImage',
	'uploadImage',
	'downloadImage',
	'translateVoice',
	'getNetworkType',
	'openLocation',
	'getLocation',
	'hideOptionMenu',
	'showOptionMenu',
	'hideMenuItems',
	'showMenuItems',
	'hideAllNonBaseMenuItem',
	'showAllNonBaseMenuItem',
	'closeWindow',
	'scanQRCode',
	'chooseWXPay',
	'openProductSpecificView',
	'addCard',
	'chooseCard',
	'openCard',
]


export default {
   
    _initWX(){
        let urlParse = utils.parseUrl(window.location.href)


        let code = urlParse.params.code
        return new Promise((resolve, reject) => {
		
			_API.userConfig({
                url: encodeURIComponent((window.location.href).split('#')[0])
            }).then(res => {
                if(res.code === 200){
						let data=res.data;
					wx.config({
                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                        appId: data.appId, // 必填，公众号的唯一标识
                        timestamp: data.timestamp, // 必填，生成签名的时间戳
                        nonceStr: data.nonceStr, // 必填，生成签名的随机串
                        signature: data.signature,// 必填，签名
                        jsApiList:jsApiList // 必填，需要使用的JS接口列表
                    })
                    wx.ready(() => {
						console.log("ready配置成功")
                        resolve()
                    }) 
				}
			})
                   
            
        })
    }
}
